#include <allegro.h>
#include "player.h"
#include "object.h"

player::player(int x, int y, int speed_x, char nome[]) {
	this->x = x;
	this->y = y;
	this->speed_x = speed_x;
	img = load_bitmap(nome, NULL);
   w = img->w;
   h = img->h;
}

void player::draw(BITMAP* buffer) {
	draw_sprite(buffer, img, x, y);
}

bool player::can_catch(object o) {
	if ( ((this->x + this->w > o.x) && (this->x < o.x + o.w)) && ((this->y + this->h > o.y) && (this->y < o.y + o.h)) )
		return true;
	return false;
}

void player::move(int w) {
   clear_keybuf();
   
   if (key[KEY_RIGHT]) {
      this->x += this->speed_x;
      if (this->x + this->w > w)
         this->x = w - this->w;
   }
   else if (key[KEY_LEFT]) {
      this->x -= this->speed_x;
      if (this->x < 0)
         this->x = 0;
   }
}